package cn.kooki.app.duobao.ui.Activity.User;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.kooki.app.duobao.R;
import cn.kooki.app.duobao.base.BaseNavActivity;
import cn.kooki.app.duobao.data.bus.ChangePageEvent;
import cn.kooki.app.duobao.data.bus.OnRequestEvent;
import cn.kooki.app.duobao.ui.Adapter.TabAdapter;
import cn.kooki.app.duobao.ui.Fragment.duobaorecord.DuobaoRecordItemFragment;

/**
 * Created by xiong on 2015/12/13.
 */
public class DuobaoRecordActivity extends BaseNavActivity {
    @Bind(R.id.tabs)
    TabLayout tabs;
    @Bind(R.id.view_pager)
    ViewPager viewPager;
    private DuobaoRecordItemFragment allfragment;
    private DuobaoRecordItemFragment currtfragment;
    private DuobaoRecordItemFragment reslutfragment;
    private TabAdapter adapter;
    private int type;

    @Override
    public void setLayoutContainerView() {
        setContainerView(R.layout.activity_duobao_record);
        ButterKnife.bind(this);
    }

    @Override
    protected void afterView() {
        Bundle allbundle = new Bundle();
        allbundle.putInt("type", DuobaoRecordItemFragment.ALL_TYPE);

        Bundle currtbundle = new Bundle();
        currtbundle.putInt("type", DuobaoRecordItemFragment.CURRT_TYPE);

        Bundle resultbundle = new Bundle();
        resultbundle.putInt("type", DuobaoRecordItemFragment.RESULT_TYPE);

        allfragment = new DuobaoRecordItemFragment();
        currtfragment = new DuobaoRecordItemFragment();
        reslutfragment = new DuobaoRecordItemFragment();
        allfragment.setArguments(allbundle);
        currtfragment.setArguments(currtbundle);
        reslutfragment.setArguments(resultbundle);
        adapter = new TabAdapter(getSupportFragmentManager());
        adapter.addFragment(allfragment, "全部");
        adapter.addFragment(currtfragment, "进行中");
        adapter.addFragment(reslutfragment, "已揭晓");
        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(3);
        tabs.setupWithViewPager(viewPager);
        topTextCenter.setText(R.string.title_activity_duobao_record);
        topTextCenter.setVisibility(View.VISIBLE);
        type = getIntent().getIntExtra("type", 0);
        viewPager.setCurrentItem(type);
    }


    public void onEventMainThread(ChangePageEvent event) {
        if (event.item == 0) {
            finish();
        }
    }
}
